import top100.twopointer.Solution287;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/28 13:59
 * @description:
 */
public class Solution2073 {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int sum = 0;
        for (int i = 0; i < tickets.length; i++) {
            if (i <= k) {
                sum += Math.min(tickets[i], tickets[k]);
            } else {
                sum += Math.min(tickets[i], tickets[k] - 1);
            }

        }
        return sum;
    }

    public static void main(String[] args) {
        Solution2073 solution = new Solution2073();
        System.out.println(solution.timeRequiredToBuy(new int[]{84, 49, 5, 24, 70, 77, 87, 8}, 3));
    }
}
